﻿using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;


namespace RimZombieGirl
{
    public class LearnAbilityLimitedSkill
    {
        public static void Notify_BookRead(Pawn pawn, Book book)
        {
            Book_AbilityLimitSkill book_abilityLimitedSkill = book as Book_AbilityLimitSkill;
            bool flag = book_abilityLimitedSkill != null;
            if (flag)
            {
                List<Ability> Abilities = pawn.abilities.abilities;
                bool flag2 = Abilities != null;
                int skilllevel = pawn.skills.skills.FirstOrDefault((SkillRecord x) => x.def == book_abilityLimitedSkill.skillDef).Level;
                bool skillLimit = skilllevel >= book_abilityLimitedSkill.skillLevelsLimit;
                if (flag2&& skillLimit)
                {
                    pawn.abilities.GainAbility(book_abilityLimitedSkill.psycast);
                    pawn.TryGetInnerInteractableThingOwner()?.Remove(book);
                    if (!book.Destroyed)
                    {
                        book.Destroy(DestroyMode.Vanish);
                    }

                }
            }
        }
    }
}
